const express = require('express');
// 引入express的websocket
const expressWs = require('express-ws')

var router = express.Router();

expressWs(router); 

// 捕获客户端的连接，建立websocket的通讯
router.ws("/ws", (ws, req) => {

  // 当客户端有消息时
  ws.on("message",(msg) => {

    console.log("接收数据：",msg);
    ws.send("服务端发送数据")
    
  })

  // ws.

  ws.on("close",() => {
    console.log("客户端关闭");
  })


})

module.exports = router;